//
//  TimeCelll.m
//  cactus
//
//  Created by li hongdan on 12-4-17.
//  Copyright (c) 2012年 ifeng. All rights reserved.
//

#import "TimeCell.h"
#import "Sgr_macro.h"
#import "CLGloble.h"
#import "UIView+Utils.h"
@interface TimeCell()
@property (nonatomic,strong) UILabel *timeLabel;
@property (nonatomic,strong) UIImageView *iconCount;
@property (nonatomic,strong) UIButton *commentButton;

@property (nonatomic , strong) UIViewController *controller;
@end
@implementation TimeCell
@synthesize commentDelegate,iconCount,commentButton;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        UIFont *timeFont=[UIFont systemFontOfSize:11.0f];
        self.timeLabel=[[UILabel alloc] init];
        self.timeLabel.backgroundColor=[UIColor clearColor];
        self.timeLabel.font=timeFont;
        self.timeLabel.textAlignment = NSTextAlignmentLeft;
        self.timeLabel.textColor=RGB(0x56, 0x56, 0x5e);
        [self addSubview:self.timeLabel];
        
        
        self.commentButton=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.commentButton addTarget:self action:@selector(pressComment) forControlEvents:UIControlEventTouchUpInside];
        self.commentButton.hidden = YES;
        self.commentButton.backgroundColor=[UIColor clearColor];//ICurrentTheme.docStyle.docCommentBacegroundColor;

        self.commentButton.frame=CGRectMake(162, 3.0f, 55.0f, 22.0f);
        [self addSubview:self.commentButton];
        
        self.iconCount=[[UIImageView alloc] init];
        self.iconCount.backgroundColor = [UIColor clearColor];
        self.iconCount.image=[UIImage imageNamed:@"index_commentCount_icon.png"];
        self.iconCount.frame=CGRectMake(10, 7.0f, 10.0f, 10.0f);
        [self.commentButton addSubview:self.iconCount];
        
        
        UIFont *comFont=[UIFont systemFontOfSize:10.0f];
        commentLabel=[[UILabel alloc] init];
        // commentLabel.frame=CGRectMake(26.0f, 5.0f, 48.0f, comFont.lineHeight);
        commentLabel.frame=CGRectMake(10.0f+10+4, 4.0f, 7.0f, 10.0f);
        commentLabel.textColor=RGB(0x5b, 0x85, 0x9e);
        commentLabel.backgroundColor=[UIColor clearColor];
        commentLabel.text=@"0";
        commentLabel.font=comFont;
        [self.commentButton addSubview:commentLabel];

    }
    return self;
}

-(void)setCommentHidden{
  self.commentButton.hidden=YES;
}
- (void)pressComment{
    if(commentDelegate && [commentDelegate  respondsToSelector:@selector(goToComment)]){
        [commentDelegate performSelector:@selector(goToComment)];
    }
}

- (void)setTime:(NSString *)time{
    
    self.timeLabel.text=time;
    UIFont *fnt = [UIFont systemFontOfSize:11.f];
    self.timeLabel.font = fnt;
    // 根据字体得到NSString的尺寸
    CGSize size = [self.timeLabel.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];
    self.timeLabel.frame = CGRectMake(12, 6.0f, size.width, 11);
}

- (void)setComentNum:(int)count{
    if (count && count>0) {
        
        self.commentButton.hidden = NO;
        
        NSString *comCountStr=[NSString stringWithFormat:@"%d",count];
        if(_isStrNULL(comCountStr))return;
        
        commentLabel.text=[NSString stringWithFormat:@"%d",count];
        UIFont *fnt = [UIFont systemFontOfSize:10.f];
        commentLabel.font = fnt;
        // 根据字体得到NSString的尺寸
        CGSize size = [commentLabel.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];
        commentLabel.frame=CGRectMake(10.0f+10+4, 4.0f, size.width, 10);
        
        self.iconCount.frame=CGRectMake(10.0f, 5.0f, 10.0f, 10.0f);
        CGRect cbButtonRect=self.commentButton.frame;
        cbButtonRect.size.width=size.width+37.0f;
        cbButtonRect.origin.x=self.timeLabel.right;
        self.commentButton.frame=cbButtonRect;
    }else{
        self.commentButton.hidden = YES;
    }
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
